package git.bankview.wl.report;

import java.util.*;
import java.sql.*;
import java.io.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.sl.report.ReportCommon;
import git.bankview.sl.report.SchdUtil;

import org.apache.log4j.Logger;

public class QueryMethodActivity
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(QueryMethodActivity.class);
	
	private static final String SQL_SELECTOR =
		"select count(*) from transmethod where transid = ? and methodid = ?";
		
	/**
	 *
	 */
	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] vParam = oCtx.getActivityParameter().split(":");
		String transid = (String)oCtx.getField("transid");
		String methodid = vParam[1];
		String resultField = vParam[0];
		
		Connection oConn = DBConnectionFactory.getCoreConnection();
		try
		{
			PreparedStatement ps = oConn.prepareStatement(SQL_SELECTOR);
			ps.setString(1, transid);
			ps.setString(2, methodid);
			ResultSet rs = ps.executeQuery();
			int r = 0;
			if (rs.next())
			{
				r = rs.getInt(1);
			}
			
			oCtx.setField(resultField, String.valueOf(r));
		}
		finally
		{
			oConn.close();
		}
	}
}
